package com.iflysse.dao;

import com.iflysse.pojo.bo.req.ResourceKnowledgePointPoReq;
import com.iflysse.pojo.po.common.CommonPoResp;
import com.iflysse.pojo.po.req.KnowledgePointPoReq;
import com.iflysse.pojo.po.resp.KnowledgePointPoResp;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.sql.SQLException;
import java.util.List;

@Repository
public interface KnowledgePointDao {

    /**
     * 根据父节点获取知识点
     * @param knowledgePointPoReq
     * @return
     */
    @Select({"select * from tb_knowledge_point where knowledge_point_parent_id = #{knowledegPointId}"})
    @Results({
            @Result(property = "knowledgePointId",column = "knowledge_point_id"),
            @Result(property = "knowledgePointParentId",column = "knowledge_point_parent_id"),
            @Result(property = "knowledgePointName",column = "knowledge_point_name"),
            @Result(property = "orderIndex",column = "order_index"),
    })
    List<KnowledgePointPoResp> getKnowledgePointsByParentId(KnowledgePointPoReq knowledgePointPoReq) throws SQLException;


    /**
     * 将知识点和资源绑定
     * @param resourceKnowledgePointPoReq
     * @return
     */
    @Insert({
            "<script>",
            "insert into tb_resource_knowledge_point (resource_knowledge_point_id,resource_id,knowledge_point_id) values  "+
            "<foreach collection='knowledgePointIdList' item='item' index='index' separator=','>"+
            "(uuid(), #{resourceId}, #{item}) "+
            "</foreach>"+
            "</script>"
    })
    @Options(useGeneratedKeys = true, keyProperty = "resource_knowledge_point_id")
    int addKnowledgePointToResource(ResourceKnowledgePointPoReq resourceKnowledgePointPoReq) throws SQLException;
}
